﻿//Plugin_Warranty
//Copyright (c) 2011 by Mattias Benninge

//This is a plugin for SCCM Client Center (SMSCliCtrV2 by Roger Zander)

//This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. 
//This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
//GNU General Public License: http://www.gnu.org/licenses/gpl.html

using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Drawing;
using System.Management;
using System.IO;
using smsclictr.automation;
using Microsoft.Win32;
using System.Xml;

namespace SMSCliCtrV2
{
    public class Tools
    {
        internal static Assembly MyAssembly;
 
        public static string[] GetPlugins
        {
            get
            {
                try
                {
                    //Get the path from SMSCliCtrV2.exe
                    string sPath = new FileInfo(Assembly.GetCallingAssembly().Location).DirectoryName;
                    //Load the automation library from the same path as smsclictrv2.exe
                    MyAssembly = Assembly.LoadFrom(Path.Combine(sPath, "smsclictr.automation.dll"));
                }
                catch
                {
                }

                return new string[] { "Warranty"};
            }
        }

        public void Warranty(object sender)
        {
            if (sender.GetType() == typeof(ToolStripMenuItem))
            {
                ((ToolStripMenuItem)sender).Click += new EventHandler(Warranty_Click);
                ((ToolStripMenuItem)sender).ToolTipText = Plugin_Warranty.Properties.Resources.WarrantyInfoTip;
                ((ToolStripMenuItem)sender).Image = Plugin_Warranty.Properties.Resources.Warranty.ToBitmap();
             
            }
        }


        void Warranty_Click(object sender, EventArgs e)
        {
            MainForm aFrom = new MainForm();
            aFrom.StartPosition = FormStartPosition.CenterScreen;
            aFrom.ShowDialog();
        }

        #region XML Settings

        //Get the XML Config-File
        internal string ConfigPath
        {
            get
            {
                //Get XML Settings
                return Assembly.GetExecutingAssembly().Location + ".config";
            }
        }

        /// <summary>
        /// Get an XML Property
        /// </summary>
        /// <param name="SettingName">XML Property Name</param>
        /// <returns>Property value</returns>
        internal string GetConfigString(string SettingName)
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(ConfigPath);
                return xDoc.SelectSingleNode(string.Format("//configuration/applicationSettings/Plugin_Warranty.Properties.Settings/setting[@name='{0}']", SettingName)).InnerText;
            }
            catch { }

            //return default value
            return Plugin_Warranty.Properties.Settings.Default[SettingName].ToString();
        }

        
        /*internal string GetConnectionString(string ConnectionStringName)
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(ConfigPath);
                return xDoc.SelectSingleNode(string.Format("//connectionStrings/add[@name='{0}']", ConnectionStringName)).Attributes["connectionString"].Value;
            }
            catch { }

            //return default value
            return Plugin_Warranty.Properties.Settings.Default.SQLConnection;
        } */

        #endregion
    }
}
